<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
   
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <title>login</title>
</head>

<body>
    <div id="app">

        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="用户名">
                <el-input v-model="user.username" placeholder="用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="user.password" placeholder="密码"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="login">查询</el-button>
            </el-form-item>
        </el-form>
    </div>
    <script>
        axios.defaults.withCredentials=true;
        new Vue({
            el: "#app",
            data() {
                return {
                    user: {
                        username: '',
                        password: ''
                    }
                }
            },
            methods:{
                login:function(){
                    let _this = this;
                    // 为给定 ID 的 user 创建请求
                    axios.get('http://localhost:8090/api/user/login?username='+this.user.username+"&password="+this.user.password)
                        .then(function (response) {
                            console.log(response.data.results);
                            localStorage.setItem("user",response.data.results)
    
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                }
            }
        });
    </script>
</body>

</html>